package test0103.test02;

public class Company {
    String name;
    Department[] arr = new Department[2];
    int i = 0;

    public Company() {
    }

    public Company(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Company{" +
                "name='" + name + '\'' +
                '}';
    }

    public void addDepartment(Department Department) {
        arr[i] = Department;
        i++;
    }


    public Department getDepartmentByName(String dname) {
        for (Department d : arr) {
            if (d.getDname()==dname){
                return d;
            }
        }
        return null;
    }

    public Position getPositionByName(String pname) {
        for (Department d : arr) {
            for (Position position: d.positions){
                if (position.getPname() ==pname){
                    return position;
                }
            }
        }
        return null;
    }

    public Employee getEmployeeByName(String ename) {
        for (Department d : arr) {
            for (Position position: d.positions){
                for (Employee employee: position.employees){
                    if (employee.getEname() == ename){
                        return employee;
                    }
                }
            }
        }
        return null;
    }
}
